package org.southyin.controller.cms_article;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.southyin.model.CmsArticle;
import org.southyin.service.CmsArticleService;
import org.southyin.service.impl.CmsArticleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/article/details")
public class CmsArticleByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        CmsArticleService service = new CmsArticleServiceImpl();
        CmsArticle article = service.getArticleById(Long.valueOf(id));
        resp.getWriter().println(new ObjectMapper().writeValueAsString(article));
    }
}
